class ProjectEditor
  attr_accessor :panel,:attEdit,:n
  def initialize(pane)
    @panel = Wx::Panel::new pane
    @panel.set_sizer(Wx::BoxSizer::new(Wx::VERTICAL))
    siz = Wx::StaticBoxSizer::new(Wx::VERTICAL,@panel,"Editor")
    @attEdit=Wx::TextCtrl::new(@panel,:style=>Wx::TE_MULTILINE)
    siz.add @attEdit,Wx::ALL|Wx::GROW,Wx::EXPAND
    @panel.sizer.add siz,Wx::ALL|Wx::GROW,Wx::EXPAND
    siz1 = Wx::BoxSizer::new(Wx::VERTICAL)
#     @panel.sizer.add(50,50)
    @panel.sizer.add siz1
    sizb = Wx::BoxSizer::new Wx::HORIZONTAL
    sizb.add Wx::Button::new(@panel,2234,"Commit change to YAML DataBase")
    sizb.add Wx::Button::new(@panel,3324,"Format")
    sizb.add Wx::Button::new(@panel,3325,"De-Format")
    sizb.add Wx::Button::new(@panel,3326,"Hilight")
    @panel.evt_button(3324) {|evt|
#       @attEdit.value = format(@attEdit.value)
      colourCode(@attEdit.value,@attEdit)
    }
    @panel.evt_button(3326) {|evt|
#       @attEdit.value = format(@attEdit.value)
      colourCode(@attEdit.value,@attEdit,0)
    }
    @panel.evt_button(3325) {|evt|
      @attEdit.value = unformat(@attEdit.value)
    }
    siz1.add sizb
    @panel.evt_button(2234) {|evt|
      pane.activeObjectEdit.update(@attEdit.value)
    }
    siz1.add 10,10
    siz4 = Wx::StaticBoxSizer::new(Wx::VERTICAL,@panel,"Attribute Manager")
    siz2 = Wx::BoxSizer::new(Wx::HORIZONTAL)
    siz4.add siz2
    siz1.add siz4
    siz2.add Wx::StaticText::new(@panel,-1,"YAML Db object file:")
    siz2.add 20,20
    file = Wx::TextCtrl::new(@panel,-1)
    siz2.add file
    siz2.add 20,20
    @n = Wx::TextCtrl::new(@panel)
    siz2.add 20,20
    siz2.add Wx::Button::new(@panel,2235,"Choose")
    @panel.evt_button(2235) {|evt|
     dlg = Wx::FileDialog.new(@panel, "Choose a object config file",
     "", "", "Object Config Files(*.ocfg)|*.ocfg",
     Wx::OPEN, Wx::DEFAULT_POSITION)    #
     dlg.set_directory("#{Dir.getwd}/data")
     dlg.show_modal
     f = dlg.get_path
     file.value = f
    }
    siz2.add 40,20
    siz2.add Wx::StaticText::new(@panel,-1,"Attribute name:")
    siz2.add 20,20
    siz2.add @n
    siz2 = Wx::BoxSizer::new Wx::HORIZONTAL
    siz4.add 20,20
    siz4.add siz2
    siz2.add Wx::Button::new(@panel,2236,"Write to")
    @panel.evt_button(2236) {|evt|
      if $pobjects.find {|po| po[1].cfg==file.value}
        $pobjects.find {|po| po[1].cfg==file.value}.attributes[:and][@n.value]=@attEdit.value
        $pobjects.find {|po| po[1].cfg==file.value}.write
      else
        temp = YAML.load_file(file.value)
        temp.attributes[:and][@n.value]=@attEdit.value
        temp.write
      end
      oname = YAML.load_file(file.value).oname
      proj = 0
      proj = $projects.find {|pr| pr[1].objects.index(file.value)}
# p proj;exit
#       p pane.instance_variable_get("@ptree").items.has_key?(proj.pname) and proj != 0
# exit
      if proj !=0 and proj != nil and pane.instance_variable_get("@ptree").items.has_key?(proj[1].pname)
        pane.clear_projects
        pane.load_projects()
      end
    }
    siz2.add 177,20
    choices = ["functions","commands","attributes"]
    choice = Wx::Choice::new @panel,-1,:choices=>choices
    siz2.add choice
    siz2.add 20,20
    siz2.add Wx::Button::new(@panel,2237,"Move to folder")
    @panel.evt_button(2237) {|evt|
      type = choices[choice.get_selection]
      if $pobjects.find {|po| po[1].cfg==file.value}
        $pobjects.find {|po| po[1].cfg==file.value}.instance_variable_get("@"+type)[@n.value]=@attEdit.value
        $pobjects.find {|po| po[1].cfg==file.value}.write
      else
        temp = YAML.load_file(file.value)
        temp.instance_variable_get("@"+type)[@n.value]=@attEdit.value
        temp.write
      end
      oname = YAML.load_file(file.value).oname
      proj = 0
      proj = $projects.find {|pr| pr[1].objects.index(file.value)}
# p proj;exit
#       p pane.instance_variable_get("@ptree").items.has_key?(proj.pname) and proj != 0
# exit
      if proj !=0 and proj != nil and pane.instance_variable_get("@ptree").items.has_key?(proj[1].pname)
        pane.clear_projects
        pane.load_projects()
      end
    }
#     siz = Wx::StaticBoxSizer::new(Wx::VERTICAL,@panel,"IDE/Server Interface")
#     siz.add 10,10
#     siz.add Wx::StaticText::new @panel,-1,"Ctrl+E evalutes in the ide.     Ctrl+S sends to the Mu* server."
#     siz.add 10,10
#     @attProps=MuIDE::Input::new(@panel,:style=>Wx::TE_MULTILINE)
#     siz.add @attProps,Wx::ALL|Wx::GROW,Wx::EXPAND
#     @panel.sizer.add siz,Wx::ALL|Wx::GROW,Wx::EXPAND
  end
end